﻿<phone:PhoneApplicationPage 
    x:Class="Coevery.PhoneApp.Index"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:myConverter="clr-namespace:Coevery.PhoneApp.Convert"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="728"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False" BackKeyPress="PhoneApplicationPage_BackKeyPress">

    <phone:PhoneApplicationPage.Resources>
        <myConverter:StringConverter x:Name="StringConverter"></myConverter:StringConverter>
        <myConverter:MetadataConverter x:Name="MetadataConverter"></myConverter:MetadataConverter>
        <myConverter:StatusConverter x:Name="StatusConverter"></myConverter:StatusConverter>
        <DataTemplate x:Name="LeadTemplate" >
            <StackPanel  VerticalAlignment="Top" Margin="0 10 0 0" Width="450">
                <StackPanel Orientation="Horizontal">
                    <Image Source="Images/customer.png"></Image>
                    <TextBlock Text="{Binding FullName}" Foreground="#0597d2" FontSize="26" Margin="5 0 0 0"></TextBlock>
                    <TextBlock  Foreground="#0597d2" VerticalAlignment="Center">
                        <TextBlock.Text>
                            <Binding Path="Country" StringFormat="{} ({0})"></Binding>
                        </TextBlock.Text>
                    </TextBlock>
                </StackPanel>
                <StackPanel>
                    <TextBlock Text="{Binding Subject}" Foreground="#aeb3b6" VerticalAlignment="Top" TextWrapping="Wrap"></TextBlock>
                </StackPanel>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="200"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding StatusCode, Converter={StaticResource MetadataConverter}, ConverterParameter=lead_statuscode}" Foreground="{Binding StatusCode, Converter={StaticResource StatusConverter}, ConverterParameter=lead_statuscode}" Grid.Column="0" HorizontalAlignment="Left"></TextBlock>
                    <TextBlock  Text="{Binding ModifiedOn, StringFormat=d}" Foreground="Black" Grid.Column="1" HorizontalAlignment="Right">
                    </TextBlock>
                </Grid>
                <Border BorderBrush="#eeeeee" BorderThickness="1" Margin="0 5 0 0"></Border>
            </StackPanel>
       </DataTemplate>
        <DataTemplate x:Name="OpportunityTemplate" >
            <StackPanel  VerticalAlignment="Top" Margin="0 10 0 0" Width="450">
                <StackPanel Orientation="Horizontal">
                    <Image Source="Images/customer.png"></Image>
                    <TextBlock DataContext="{Binding Customer}" Text="{Binding Name}" FontSize="26"  Foreground="#0597d2" Margin="5 0 0 0"></TextBlock>
                    <TextBlock DataContext="{Binding Customer}"  Foreground="#0597d2" VerticalAlignment="Center">
                        <TextBlock.Text>
                            <Binding Path="Country" StringFormat="{} ({0})"></Binding>
                        </TextBlock.Text>
                    </TextBlock>
                </StackPanel>
                <StackPanel>
                    <TextBlock Text="{Binding Name}" Foreground="#aeb3b6" VerticalAlignment="Top" TextWrapping="Wrap"></TextBlock>
                </StackPanel>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="200"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding StatusCode, Converter={StaticResource MetadataConverter}, ConverterParameter=opportunity_statuscode}" Foreground="{Binding StatusCode, Converter={StaticResource StatusConverter}, ConverterParameter=opportunity_statuscode}" Grid.Column="0" HorizontalAlignment="Left"></TextBlock>
                    <TextBlock  Text="{Binding ModifiedOn, StringFormat=d}"  Foreground="Black" Grid.Column="1" HorizontalAlignment="Right">
                    </TextBlock>
                </Grid>
                <Border BorderBrush="#eeeeee" BorderThickness="1" Margin="0 5 0 0"></Border>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Name="QuoteTemplate">
            <StackPanel VerticalAlignment="Top" Margin="0 10 0 0" Width="450">
                <StackPanel Orientation="Horizontal">
                    <Image Source="Images/customer.png"></Image>
                    <TextBlock DataContext="{Binding Owner}" Text="{Binding FullName}" FontSize="26" Foreground="#0597d2" Margin="5 0 0 0"></TextBlock>
                </StackPanel>
                <StackPanel>
                    <TextBlock Text="{Binding Name}" Foreground="#aeb3b6" VerticalAlignment="Top" TextWrapping="Wrap"></TextBlock>
                </StackPanel>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="200"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding StatusCode,Converter={StaticResource MetadataConverter},ConverterParameter=quote_stagecode}" Foreground="Black" Grid.Column="0" HorizontalAlignment="Left"></TextBlock>
                    <TextBlock Text="{Binding ModifiedOn,StringFormat=d}" Foreground="Black"  Grid.Column="1" HorizontalAlignment="Right"></TextBlock>
                </Grid>
                <Border BorderBrush="#eeeeee" BorderThickness="1" Margin="0 5 0 0"></Border>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Name="ContractTemplate">
            <StackPanel VerticalAlignment="Top" Margin="0 10 0 0" Width="450">
                <StackPanel Orientation="Horizontal">
                    <Image Source="Images/customer.png"></Image>
                    <TextBlock DataContext="{Binding BillingCustomer}"  Text="{Binding Name}" FontSize="26" Foreground="#0597d2" Margin="5 0 0 0"></TextBlock>
                </StackPanel>
                <StackPanel>
                    <TextBlock Text="{Binding Title}" Foreground="#aeb3b6" VerticalAlignment="Top" TextWrapping="Wrap"></TextBlock>
                </StackPanel>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="200"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding StatusCode,Converter={StaticResource MetadataConverter},ConverterParameter=contract_statuscode}" Foreground="Black" Grid.Column="0" HorizontalAlignment="Left"></TextBlock>
                    <TextBlock Text="{Binding ModifiedOn,StringFormat=d}" Foreground="Black" Grid.Column="1" HorizontalAlignment="Right"></TextBlock>
                </Grid>
                <Border BorderBrush="#eeeeee" BorderThickness="1" Margin="0 5 0 0"></Border>
            </StackPanel>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <controls:Pivot Foreground="#0597d2">
            <controls:PivotItem Header="Lead">
                <ListBox x:Name="LeadListBox" ItemsSource="{Binding Leads}" ItemTemplate="{StaticResource LeadTemplate}" SelectionChanged="LeadListBox_SelectionChanged">
                </ListBox>
            </controls:PivotItem>

            <controls:PivotItem Header="Opportunity">
                <ListBox x:Name="OpportunityListBox" ItemsSource="{Binding Opportunities}" ItemTemplate="{StaticResource OpportunityTemplate}" SelectionChanged="OpportunityListBox_SelectionChanged">
                </ListBox>
            </controls:PivotItem>
            
            <controls:PivotItem Header="Quote">
                <ListBox x:Name="QuoteListBox" ItemsSource="{Binding Quotes}" ItemTemplate="{StaticResource QuoteTemplate}" SelectionChanged="QuoteListBox_SelectionChanged">
                </ListBox>
            </controls:PivotItem>
            
            <controls:PivotItem Header="Contract">
                <ListBox x:Name="ContractListBox" ItemsSource="{Binding Contracts}" ItemTemplate="{StaticResource ContractTemplate}" SelectionChanged="ContractListBox_SelectionChanged"></ListBox>
            </controls:PivotItem>
        </controls:Pivot>
    </Grid>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" BackgroundColor="#0066cc" Opacity="10">
            <shell:ApplicationBarIconButton x:Name="btnShow" IconUri="/Images/appbar.list.rest.png" Text="Show All" Click="ShowAll_Click"/>
            <shell:ApplicationBarIconButton x:Name="btnRefresh" IconUri="/Images/appbar.refresh.rest.png" Text="Refresh" Click="Refresh_Click"/>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>